package com.example.bausip;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class AddQuestionActivity extends Activity {
	ArrayList<NameEntity> questions;
	ArrayList<Item> questionItems;
	MyCustomAdapter dataAdapter;
	int course_id =0;
	TextView uniId,bodyLabel,courseLabel,questionLabel;
	EditText answer;
	Question current;
	CheckBox ispublic;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_question);
		Bundle extras = getIntent().getExtras();
		if(extras!=null)
		{
			course_id = extras.getInt("course_id");
		}
		courseLabel = (TextView) findViewById(R.id.courseLabel);
		courseLabel.setText(""+course_id);
		bodyLabel = (TextView) findViewById(R.id.bodyLabel);
		questionLabel = (TextView) findViewById(R.id.questionLabel);
		//?question_title=shi&question_text=shi2&student_id=103&question_parent_id=1
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.question, menu);
		return true;
	}
	public void askQuestion(View v)
	{
		String title = questionLabel.getText().toString();
		String body = bodyLabel.getText().toString();
		int parent_id = 0;
		int studentId = sip.getUserId();
		
		String serverURL = new myURL("ask_question.php?question_parent_id="+parent_id+
				"&student_id="+studentId+"&question_title="+title+"&question_text="+body+"&course_id="+course_id,true).getURL();
		RZHelper p = new RZHelper(serverURL, this, "done", true);
		p.get();
	}
	public void done(String s,String error)
	{
		Toast.makeText(getApplicationContext(), "Question submitted successfully", Toast.LENGTH_SHORT)
	      .show();
		Intent intent = new Intent(this, QuestionsActivity.class);
		intent.putExtra("type", "my");
		startActivity(intent);
	}
}
